package o;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.huawei.appgallery.appcomment.impl.bean.AppInfoBean;
import com.huawei.appgallery.appcomment.impl.bean.GetCommentResBean;
import com.huawei.appgallery.appcomment.ui.AppCommentFragment;
import com.huawei.appgallery.appcomment.ui.adapter.AppCommentListAdapter;
import com.huawei.appgallery.appcomment.ui.view.AppScoreView;
import com.huawei.appgallery.appcomment.ui.view.CommentDevItemView;
import com.huawei.appgallery.appcomment.ui.view.CommentListView;
import com.huawei.appgallery.appcomment.ui.view.CommentTitleView;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView.a;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import java.util.List;
import o.bcg.d;
import o.bcg.e;

public class bdy implements beb {
    private c ʻ;
    private boolean ʼ = false;
    private ImageView ʽ;
    private bdm ˊ;
    private int ˊॱ = 0;
    private CommentTitleView ˋ;
    private CommentDevItemView ˋॱ;
    private CommentListView ˎ = null;
    private AppScoreView ˏ;
    private View ˏॱ;
    private int ͺ;
    private View ॱ;
    private View ॱˊ;
    private TaskFragment ॱˋ;
    private AppInfoBean ॱॱ;
    private String ॱᐝ;
    private AppCommentListAdapter ᐝ;
    private boolean ᐝॱ = false;

    public interface c {
        boolean ˊ(String str, int i, int i2);
    }

    public void ˏ(TaskFragment taskFragment) {
        this.ॱˋ = taskFragment;
    }

    public void ˏ(c cVar) {
        this.ʻ = cVar;
    }

    public View ˏ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ˏॱ = layoutInflater.inflate(d.ˊ, null);
        this.ˎ = (CommentListView) this.ˏॱ.findViewById(e.ˑॱ);
        this.ॱ = layoutInflater.inflate(d.ॱॱ, null);
        azb.ˏ(this.ॱ);
        this.ʽ = (ImageView) this.ॱ.findViewById(e.ʳ);
        this.ˏ = new AppScoreView(this.ˏॱ.getContext());
        this.ˎ.addHeaderView(this.ˏ);
        this.ˎ.setInterceptScrollOnTop(true);
        this.ˋ = (CommentTitleView) this.ˏ.findViewById(e.ʿˋ);
        this.ˋ.setOnFilterListener(this);
        this.ˋॱ = (CommentDevItemView) this.ˏ.findViewById(e.ﾟ);
        this.ˊ = (bdm) ((AppCommentFragment) this.ॱˋ).ˊʻ();
        this.ᐝ = new AppCommentListAdapter(this.ॱˋ.ॱˋ(), this.ˊ);
        this.ˊ.ˏ(this.ᐝ);
        if (this.ˊ.ˊ() != null && this.ˊ.ॱॱ() <= 0) {
            this.ˎ.ˊ();
            ˋ(true);
            if ((this.ˊ.ˊॱ() <= 0.0f || this.ˊ.ˏॱ()) && this.ʽ != null) {
                this.ʽ.setVisibility(0);
                this.ʼ = true;
            }
        }
        Context context = this.ॱ.getContext();
        this.ͺ = cdo.ˏ(context, 88);
        this.ͺ += this.ˊॱ;
        if (this.ʼ) {
            this.ͺ = cdo.ˏ(context, 8) + this.ͺ;
        }
        this.ॱˊ = this.ॱ.findViewById(e.ꞌॱ);
        this.ॱˊ.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener(this) {
            final /* synthetic */ bdy ˊ;

            {
                this.ˊ = r1;
            }

            public void onGlobalLayout() {
                this.ˊ.ॱˊ.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                this.ˊ.ˋ(this.ˊ.ॱˊ.getContext(), this.ˊ.ͺ, this.ˊ.ॱˊ, this.ˊ.ˏ);
            }
        });
        this.ˎ.setAdapter(this.ᐝ);
        if (this.ॱˋ instanceof a) {
            this.ˎ.setLoadingListener((a) this.ॱˋ);
        }
        this.ᐝ.cssRender(this.ॱ);
        if (this.ˎ.ˊॱ() != null) {
            this.ᐝ.cssRender(this.ˎ.ˊॱ());
        }
        return this.ˏॱ;
    }

    private void ˋ(Context context, int i, View view, View view2) {
        int i2 = 0;
        if (view != null && context != null && context.getResources() != null) {
            int height;
            int i3;
            if (view2 != null) {
                height = view2.getHeight();
                if (height == 0) {
                    view2.measure(MeasureSpec.makeMeasureSpec(0, 0), MeasureSpec.makeMeasureSpec(0, 0));
                    height = view2.getMeasuredHeight();
                }
                i3 = height + 0;
            } else {
                i3 = 0;
            }
            if (context instanceof Activity) {
                Activity activity = (Activity) context;
                try {
                    if (activity.getActionBar() != null) {
                        i2 = activity.getActionBar().getHeight();
                    }
                    i3 = cdo.ˎ(context) - (((i3 + (i2 + cdo.ˋ(context))) + i) + this.ˊॱ);
                    LayoutParams layoutParams = view.getLayoutParams();
                    if (layoutParams instanceof LinearLayout.LayoutParams) {
                        if (i3 < cdo.ˏ(activity, 100)) {
                            height = cdo.ˏ(activity, 100);
                        } else {
                            height = i3;
                        }
                        layoutParams.height = height;
                    }
                    view.setLayoutParams(layoutParams);
                } catch (Exception e) {
                    bcb.ˋ.ˎ("AppCommentCard", "setNoDataDefaultLayoutParams catch an exception:" + e.toString());
                }
            }
        }
    }

    public boolean ˋ(List<JsonBean> list) {
        if (list == null || list.size() <= 0) {
            return false;
        }
        this.ॱॱ = (AppInfoBean) list.get(0);
        if (this.ॱॱ == null) {
            return false;
        }
        this.ᐝ.setDetailCommentBean(this.ॱॱ);
        this.ˋॱ.ˎ(this.ˊ.ॱˊ());
        ᐝ();
        return true;
    }

    private void ˋ(boolean z) {
        if (z) {
            try {
                this.ˎ.removeFooterView(this.ॱ);
                this.ˎ.addFooterView(this.ॱ);
                return;
            } catch (Throwable e) {
                bcb.ˋ.ˊ("AppCommentCard", "setNoCommentsVisibility error", e);
                return;
            }
        }
        this.ˎ.removeFooterView(this.ॱ);
    }

    public void ˊ() {
        if (this.ˎ != null && this.ˎ.ˊॱ() != null) {
            this.ᐝ.cssRender(this.ˎ.ˊॱ());
        }
    }

    public void ˏ() {
        if (this.ˎ != null) {
            this.ˎ.ʻ();
        }
    }

    public void ˊ(boolean z, BaseRequest o_cvu, ResponseBean responseBean) {
        if (z) {
            bdi o_bdi = (bdi) o_cvu;
            ˎ(o_bdi, (GetCommentResBean) responseBean);
            if (o_bdi.ˎ() == 1 && "1".equals(this.ॱᐝ) && this.ˊ.ॱ() + this.ˊ.ˎ() > 0) {
                this.ˎ.post(new Runnable(this) {
                    final /* synthetic */ bdy ˏ;

                    {
                        this.ˏ = r1;
                    }

                    public void run() {
                        this.ˏ.ˎ.smoothScrollToPosition((this.ˏ.ˊ.ॱ() + this.ˏ.ˊ.ˎ()) + 3);
                    }
                });
            }
            this.ᐝ.notifyDataSetChanged();
            return;
        }
        this.ˎ.ॱˊ();
    }

    private void ˎ(bdi o_bdi, GetCommentResBean getCommentResBean) {
        if (getCommentResBean.ˋ() == null || getCommentResBean.ˋ().size() <= 0) {
            this.ˎ.ˊ();
            this.ᐝ.cssRender(this.ॱ);
            if (o_bdi.ˎ() == 1) {
                ˋ(true);
                this.ॱ.setVisibility(0);
                if ((this.ˊ.ˊॱ() <= 0.0f || this.ˊ.ˏॱ()) && this.ʽ != null) {
                    this.ʽ.setVisibility(0);
                    this.ʼ = true;
                }
                ᐝ();
                this.ˋॱ.ˎ(this.ˊ.ॱˊ());
                return;
            }
            return;
        }
        this.ॱ.setVisibility(8);
        ˋ(false);
        if (o_bdi.ˎ() == 1) {
            ᐝ();
            this.ˋॱ.ˎ(this.ˊ.ॱˊ());
        }
    }

    private void ᐝ() {
        this.ˋ.setTitleViewByType(CommentTitleView.d.AllComment);
        this.ˋ.setFilterChecked(this.ॱॱ.ˋ(), this.ॱॱ.ॱ(), this.ॱॱ.ˊ());
        this.ˋ.setIsSpinnerClick(false);
        this.ˏ.setData(this.ˊ.ˊॱ(), this.ˊ.ͺ(), this.ˊ.ʻ(), this.ˊ.ʽ());
        this.ᐝ.cssRender(this.ˏ);
    }

    public void ˋ() {
        this.ˊ = null;
        this.ॱॱ = null;
    }

    public boolean ˎ() {
        if (this.ˎ == null || this.ˎ.canScrollVertically(-1)) {
            return false;
        }
        return true;
    }

    public void ॱ() {
        if (this.ˎ != null) {
            this.ˎ.post(new Runnable(this) {
                final /* synthetic */ bdy ˎ;

                {
                    this.ˎ = r1;
                }

                public void run() {
                    if (this.ˎ.ˎ != null) {
                        this.ˎ.ˎ.smoothScrollToPositionFromTop(0, 0);
                    }
                }
            });
        }
    }

    public void ˋ(String str, int i, int i2) {
        if (this.ʻ != null) {
            this.ॱᐝ = str;
            this.ʻ.ˊ(str, i, i2);
        }
        if (this.ॱॱ != null) {
            this.ॱॱ.ॱ(str);
            this.ॱॱ.ˊ(i);
            this.ॱॱ.ˎ(i2);
        }
    }
}
